package com.lingxi.d1_1;

import javax.sound.sampled.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MusicPlayer {
    public static void main(String[] args)
    {
        test();

    }
    public static void test()
    {

// 获取目录下的所有音乐文件
        File directory = new File("com/lingxi/d1_1");
        File[] files = directory.listFiles((d, name) -> name.endsWith(".mp3")); // 以.mp3为例
        playSong(new File("C:\\PGtest\\javastaircase\\study\\Study\\src\\com\\lingxi\\d1_1\\01. 迷星叫.wav"));
        while(1 == 1);
//        for (File : files) {
//            playSong(file);

//        }
    }
    static void playSong(File file) {
        try (AudioInputStream audioIn = AudioSystem.getAudioInputStream(file)) {
            Clip clip = AudioSystem.getClip();
            clip.open(audioIn);
            clip.start(); // 开始播放
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
